#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int which, prio,new_prio;
  id_t who;
  if (argc != 4 || strchr("pgu", argv[1][0]) == NULL)
    printf("Usage: %s {p|g|u} who priority\n",argv[0]);
  which = (argv[1][0] == 'p')?PRIO_PROCESS : 
    (argv[1][0] == 'g') ? PRIO_PGRP : PRIO_USER;
  who = atoi(argv[2]);
  new_prio = atoi(argv[3]);

  prio = getpriority(which,who);
  if (prio == -1 && errno != 0)
    printf("Failed to get priority\n");
  printf("Nice value = %d\n",prio);

  if (setpriority(which, who, new_prio) == -1)
    printf("failed to set priority\n");

  errno = 0;
  prio = getpriority(which,who);
  if (prio == -1 && errno != 0)
    printf("Failed to get priority\n");
  printf("Nice value = %d\n",prio);
  return 0;
}
